/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ${USER}
 * Date: ${YEAR}-${MONTH}-${DAY}
 * Time: ${TIME}
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        TreeNode root1 = p;
        TreeNode root2 = q;
        if (root1 == null&&root2 == null) {
            return true;
        }
        if (root1 == null&&root2 != null||root1 != null&&root2 == null) {
            return false;
        }
        if (root1.val != root2.val) return false;
        if (isSameTree(root1.left,root2.left)) {
            if (isSameTree(root1.right,root2.right)) {
                return true;
            }
            return false;
        }
        return false;
    }
}